package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.orderB.entity.ApplyCustoms;
import com.egao.orderB.service.ApplyCustomsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 *
 * 报关
 * @author : Doman
 * @date : 2021-07-21 14:58:25
 * @version ：1.0
 */

@Api(tags = "报关")
@RestController
@RequestMapping("/api/orderB/applyCustoms")
public class ApplyCustomsController extends BaseController {

	@Autowired
	private ApplyCustomsService applyCustomsService;

	/**
	 * 分页查询列表
	 */
//	@PreAuthorize("hasAuthority('orderB:applyCustoms:list')")
    //@OperLog(value = "报关", desc = "分页查询")
    @ApiOperation(value ="分页查询报关",notes = "" +
        "limit:每页显示几行 必填\n" +
        "page:第几页 必填\n" +
        "customer: 客户\n" +
        "customsBroker: 报关行\n" +
        "billOfLading: 提单号\n" +
        "date1: 创建时间\n" +
        "date2: 创建时间\n" +
        " \n\n\n" +
        "返回的结果:\n" +
        "所有的文件都放到这个方法里 registerCustomer:\n" +
        "id:id\n" +
        "customerId:客户id\n" +
        "customer:客户\n" +
        "customsBroker: 报关行\n" +
        "invoiceFile:发票\n" +
        "packageFile:装箱单\n" +
        "customFile:报关单\n" +
        "contractFile:合同\n" +
        "whereApply: 哪里报关\n" +
        "releasePermit: 放行单\n" +
        "payable: 应付金额\n" +
        "receivable: 应收金额\n" +
        "customsDate:报关时间\n" +
        "createTime:创建时间\n" +
        "createUser:创建人\n" +
        "updateTime:更新时间\n" +
        "updateUser:更新人\n" +
        "",httpMethod = "POST")
    @ApiPageParam
    @PostMapping("/list")
    public JsonResult page(PageResult2<T> page, ApplyCustoms applyCustoms) throws Exception{
        return applyCustomsService.list(page, applyCustoms, getLoginUser());
    }

	/**
	 * 分页查询列表
	 */
//	@PreAuthorize("hasAuthority('orderB:applyCustoms:list')")
    //@OperLog(value = "报关", desc = "分页查询")
    @ApiOperation(value ="分页查询报关",notes = "" +
        "limit:每页显示几行 必填\n" +
        "page:第几页 必填\n" +
        "customer: 客户\n" +
        "customsBroker: 报关行\n" +
        "billOfLading: 提单号\n" +
        "date1: 创建时间\n" +
        "date2: 创建时间\n" +
        "",httpMethod = "POST")
    @ApiPageParam
    @PostMapping("/listDel")
    public JsonResult listDel(PageResult2<T> page, ApplyCustoms applyCustoms) throws Exception{
        return applyCustomsService.listDel(page, applyCustoms, getLoginUser());
    }

    /**
     * 查询全部报关
     */
//    @PreAuthorize("hasAuthority('orderB:applyCustoms:list')")
    //@OperLog(value = "报关", desc = "查询全部")
    @ApiOperation("查询全部报关")
    @PostMapping("/listAll")
    public JsonResult list(ApplyCustoms applyCustoms){
        return applyCustomsService.list(applyCustoms, getLoginUser());
    }


    @PostMapping("/listOpen")
    @ApiOperation(value = "报关展开查询",notes = "" +
            "id:报关id\n" +
            "\n",httpMethod = "POST")
    public JsonResult listOpen(ApplyCustoms applyCustoms, HttpServletRequest request) {
        return applyCustomsService.listOpen(applyCustoms, getLoginUser());
    }

    /**
     * 根据id查询报关
     */
//    @PreAuthorize("hasAuthority('orderB:applyCustoms:list')")
    //@OperLog(value = "报关", desc = "根据id查询")
    @PostMapping("/get")
    @ApiOperation(value ="根据id查询报关",notes = "" +
            "id:id\n" +
            "",httpMethod = "POST")
    public JsonResult get(ApplyCustoms applyCustoms) {
        return applyCustomsService.getById(applyCustoms);
		// 使用关联查询
        //PageParam<applyCustoms> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<applyCustoms> records = applyCustomsService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加报关
     */
//    @PreAuthorize("hasAuthority('orderB:applyCustoms:save')")
    @OperLog(value = "报关", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加报关",notes = "" +
            "billId:拖车id\n" +
            "customerId:客户id\n" +
            "customer:客户\n" +
            "customsBroker: 报关行\n" +
            "billOfLading: 提单号\n" +
            "invoiceFile:发票\n" +
            "packageFile:装箱单\n" +
            "customFile:报关单\n" +
            "contractFile:合同\n" +
            "whereApply: 哪里报关\n" +
            "releasePermit: 放行单\n" +
            "payable: 应付金额\n" +
            "receivable: 应收金额\n" +
            "customsDate:报关时间\n" +
        "",httpMethod = "POST")
    @PostMapping("/save")
    public JsonResult save(Model model, ApplyCustoms applyCustoms) {
        return applyCustomsService.save(applyCustoms, getLoginUser());
    }


    /**
     * 放行
     */
//    @PreAuthorize("hasAuthority('orderB:applyCustoms:update')")
    @OperLog(value = "放行", desc = "放行", param = false, result = true)
    @ApiOperation(value ="放行",notes = "" +
            "id:id\n" +
            "customFile:报关单\n" +
            "releasePermit: 放行单\n" +
        "",httpMethod = "POST")
    @PostMapping("/release")
    public JsonResult release(Model model, ApplyCustoms applyCustoms) {
        return applyCustomsService.release(applyCustoms, getLoginUser());
    }
    /**
     * 修改报关
     */
//    @PreAuthorize("hasAuthority('orderB:applyCustoms:update')")
    @OperLog(value = "报关", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改报关",notes = "" +
            "id:id\n" +
            "customerId:客户id\n" +
            "customer:客户\n" +
            "customsBroker: 报关行\n" +
            "billOfLading: 提单号\n" +
            "invoiceFile:发票\n" +
            "packageFile:装箱单\n" +
            "customFile:报关单\n" +
            "contractFile:合同\n" +
            "whereApply: 哪里报关\n" +
            "releasePermit: 放行单\n" +
            "payable: 应付金额\n" +
            "receivable: 应收金额\n" +
            "customsDate:报关时间\n" +
        "",httpMethod = "POST")
    @PostMapping("/update")
    public JsonResult update(Model model, ApplyCustoms applyCustoms) {
        return applyCustomsService.update(applyCustoms, getLoginUser());
    }

    /**
     * 删除报关
     */
//    @PreAuthorize("hasAuthority('orderB:applyCustoms:remove')")
    @OperLog(value = "报关", desc = "删除", result = true)
    @ApiOperation("删除报关")
    @PostMapping("/remove")
    public JsonResult remove(ApplyCustoms applyCustoms ) {
        return applyCustomsService.remove(applyCustoms, getLoginUser());
    }

    /**
     * 批量添加报关
     */
    /**@RequiresPermissions("orderB:applyCustoms:save")
    @OperLog(value = "报关", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<ApplyCustoms> list) {
        if (applyCustomsService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改报关
     */
    /**@RequiresPermissions("orderB:applyCustoms:update")
    @OperLog(value = "报关", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<ApplyCustoms> batchParam) {
        if (batchParam.update(applyCustomsService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除报关
     */
    /**@RequiresPermissions("orderB:applyCustoms:remove")
    @OperLog(value = "报关", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (applyCustomsService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
